﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace QLK.Database
{
    public class SupplierBLL
    {
        private SupplierDAL dal;
        public SupplierBLL()
        {
            dal = new SupplierDAL();
        }

        public Supplier GetSupplierBySupplierID(int supplierID)
        {
            if (supplierID > 0)
                return dal.GetSupplierBySupplierID(supplierID);
            return null;
        }

        public IEnumerable<Supplier> GetAllSupplier()
        {
            return dal.GetAllSupplier();
        }

        public bool DeleteSupplierBySupplierID(int supplierID)
        {
            return dal.DeleteSupplierBySupplierID(supplierID);
        }

        public bool UpdateSupplier(Supplier supplier)
        {
            // check duplicate supplier
            if (!dal.CheckDuplicateSupplierBySupplierName(supplier.SupplierName))
            {
                return dal.UpdateSupplier(supplier);                
            }
            return false;
            
        }

        public bool InsertSupplier(Supplier supplier)
        {
            if (!dal.CheckDuplicateSupplierBySupplierName(supplier.SupplierName))
            {
                return dal.InsertSupplier(supplier);
            }
            return false;
        }

        
    }
}
